/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.activity.controller;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.modules.activity.domain.dto.ActivityEditUsersDto;
import com.fzhucc.modules.activity.domain.dto.ActivityUsersAddDto;
import com.fzhucc.modules.activity.service.ActivityUsersService;
import com.fzhucc.modules.activity.domain.dto.ActivityUsersQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

/**
 * @author yyg
 * @date 2022-11-17
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "活动:报名管理")
@RequestMapping("/api/activityUsers")
public class ActivityUsersController {

    private final ActivityUsersService activityUsersService;

    @GetMapping
    @Log("查询活动报名人员")
    @ApiOperation("查询活动报名人员")
    //@PreAuthorize("@el.check('activityUsers:list')")
    public ResponseEntity<Object> queryActivityUsers(ActivityUsersQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(activityUsersService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    @PostMapping
    @Log("活动报名")
    @AnonymousAccess
    @ApiOperation("活动报名")
    /*@PreAuthorize("@el.check('activityUsers:add')")*/
    public ResponseEntity<Object> createActivityUsers(@Validated @RequestBody ActivityUsersAddDto resources){
        return new ResponseEntity<>(activityUsersService.create(resources), HttpStatus.OK);
    }

    @PutMapping
    @Log("活动报名状态审核")
    @ApiOperation("活动报名状态审核")
    //@PreAuthorize("@el.check('activityUsers:audit')")
    public ResponseEntity<Object> updateActivityUsers(@Validated @RequestBody ActivityEditUsersDto resources){
        activityUsersService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除活动报名记录")
    @ApiOperation("删除活动报名记录")
    //@PreAuthorize("@el.check('activityUsers:del')")
    public ResponseEntity<Object> deleteActivityUsers(@RequestBody Integer[] ids) {
        activityUsersService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/getMyActivity")
    @Log("查询我报名的活动")
    @ApiOperation("查询我报名的活动")
    public ResponseEntity<Object> getMyActivity(ActivityUsersQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(activityUsersService.getMyActivity(criteria, pageable), HttpStatus.OK);
    }

    @GetMapping(value = "/getActivityChType")
    @Log("获取字典activity_ch_type活动参会类型")
    @ApiOperation("获取字典activity_ch_type活动参会类型")
    @AnonymousAccess
    public ResponseEntity<Object> getActivityChType() {
        return new ResponseEntity<>(activityUsersService.getActivityChType(), HttpStatus.OK);
    }

}